#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Palabre - helloworld.py
#
# Copyright 2003-2005 Célio Conort
#
# This file is part of Palabre.
#
# Palabre is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2, or (at your option) any later version.
#
# Palabre is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with program; see the file COPYING. If not,
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.

from threading import Thread
import time

class autoSend:
    
    
    def __init__(self,server):
        
        self.server = server
        
        self.name = "autoSend"

        # Do action every second
        self.frequency = 1

        # Just to see what's happenning
        self.server.logger.info("autoSend LOADED")

        # New SendIt Timer
        tim = SendIt(self.frequency,server)

        # Starting the THREAD (not the run method)
        tim.start()

        # SendIt is still looping but we can go on
        self.server.logger.info("autoSend RETURNING")
        
        return
    
class SendIt(Thread):
    
    def __init__ (self,frequency,server):
        Thread.__init__(self)
        self.server = server
        self.frequency = frequency
        self.server.logger.info("SENDIT LOADED")
        
    def run(self):
        self.server.logger.info("SENDIT RUNNINNG")
        # looping forever
        while 1:
            # Sleeping for "frequency" second
            time.sleep(self.frequency)

            # Logging ...
            self.server.logger.info(time.ctime())

            # Sending 
            self.server.serverSendToAllClients("Hello it's "+str(time.ctime()),"SendItTimer")

    
            
